﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FDEE.Model
{
    class CPME41 : CPMBase
    {
        Dictionary<string, int[]> dicRInfo = new Dictionary<string, int[]>();
        public CPME41(string typeName, string pierNumber, eColumnType ct, eSubType st, int ww, int ll, int midww, int tww, int tmidww, int pierHeight, int rr, int dia, double up, double low, double topL, double lowL, eDB mainDB, double wwside, double llside) :
            base(typeName, pierNumber, ct, st, ww, ll, midww, tww, tmidww, pierHeight, up, low, topL, lowL, rr, dia, mainDB, wwside, llside)
        {
            dicRInfo = new Dictionary<string, int[]>();
            switch (st)
            {
                case eSubType.B:
                    dicRInfo.Add("7.1.a", new int[] { 8078, 6533, 300, 26 });
                    dicRInfo.Add("7.2.a", new int[] { 8182, 6054, 340, 4 });
                    dicRInfo.Add("7.2.b", new int[] { 8320, 6030, 380, 4 });
                    dicRInfo.Add("7.2.c", new int[] { 8389, 6019, 420, 4 });
                    dicRInfo.Add("7.2.d", new int[] { 8528, 5997, 460, 4 });
                    dicRInfo.Add("7.2.e", new int[] { 8597, 5987, 500, 4 });
                    dicRInfo.Add("7.2.f", new int[] { 8735, 5968, 540, 4 });
                    dicRInfo.Add("7.2.g", new int[] { 8804, 5959, 580, 4 });
                    dicRInfo.Add("7.2.h", new int[] { 8908, 5945, 620, 4 });
                    dicRInfo.Add("7.3.a", new int[] { 8958, 5939, 660, 4 });
                    dicRInfo.Add("7.4.a", new int[] { 8982, 5936, 700, 24 });

                    dicRInfo.Add("8.1", new int[] { 82309, 5502, 719, 4 });
                    dicRInfo.Add("8.2", new int[] { 41297, 5510, 692, 4 });
                    dicRInfo.Add("8.3", new int[] { 27669, 5524, 666, 4 });
                    dicRInfo.Add("8.4", new int[] { 20897, 5545, 642, 4 });
                    dicRInfo.Add("8.5", new int[] { 16866, 5572, 620, 4 });
                    dicRInfo.Add("8.6", new int[] { 14206, 5605, 600, 4 });
                    dicRInfo.Add("8.7", new int[] { 12330, 5645, 580, 4 });


                    break;
            }
        }

        public override void SetRebarList()
        {
            switch (SubType)
            {
                case eSubType.B:
                    SetBRebarList();
                    break;
            }
        }
        public void SetBRebarList()
        {

            #region 箍筋
            int npts = 1;
            int count = 4;
            int ini1A = 0;
            int ini2B = 0;
            int ini3A = 0;
            List<double> lst1A = new List<double>();
            double w0 = 0, l0 = 0;
            CalAngelLength(ref w0, ref l0);
            int wside = (int)Math.Round(w0, 0);
            int lside = (int)Math.Round(l0, 0);
            int a = 0;
            int b = 0;
            int c = 0;
            int d = 0;
            //1#

            double r1 = 0;
            double r0 = 0;
            double x = 0;
            double y = 0;
            double xI = 0;
            double yI = 0;


            a = (int)((Width - MidWidth) * 0.5 - 50 - wwSide - wside);
            ini1A = a;
            b = (int)(Length - 50 * 2);
            c = (int)Math.Sqrt(Math.Pow(wwSide, 2) + Math.Pow(llSide, 2)) - wside - lside;
            d = (int)(Length - llSide * 2 - lside * 2);
            npts = (GetAllStirrupNum() + 3 + 1) * 2;
            RebarList.Add(new MRCRebarRecord(1, 0, "", eDB.DB12, npts, eShapeType.MRC, a, b, c, d));

            CalArcCenter(Width * 0.5, LenUpper - 32 * 10, TopWidth * 0.5, LenUpper, Radius, LenUpper, ref r1, ref x, ref y);
            CalArcCenter(MidWidth * 0.5, LenUpper - 32 * 10, TopMidWidth * 0.5, LenUpper, Radius, LenUpper, ref r0, ref xI, ref yI);

            for (int m = 1; m <= count; m++)
            {
                //string no = "A";
                ////byte[] array = new byte[1];   //定义一组数组array
                ////array = System.Text.Encoding.ASCII.GetBytes(no); //string转换的字母
                ////int asciicode = (short)(array[0]);
                //byte[] array = new byte[1];
                //array[0] = (byte)(Convert.ToInt32(64+m)); //ASCII码强制转换二进制
                //no = Convert.ToString(System.Text.Encoding.ASCII.GetString(array));
                double le = 0;
                double lh = 0;
                switch (m)
                {
                    case 1:
                        le = a;
                        lh = (le / a) * c;
                        break;
                    case 2:
                        le = a + 36;
                        lh = (le / a) * c;
                        break;
                    case 3:
                        le = a + 36 + 101;
                        lh = (le / a) * c;
                        break;
                    case 4:
                        le = a + 36 + 101 + 125;
                        lh = (le / a) * c;
                        break;
                }
                ////int a1 =(int)(Math.Round( Math.Sqrt(Math.Pow(m * 100 - 25*m, 2)+Math.Pow(ini1A, 2)),0));
                //if (m == 10)
                //    a1 = 1121;
                RebarList.Add(new MRCRebarRecord(1, m, "", eDB.DB12, 2, eShapeType.MRC, (int)le, b, (int)lh, d));
                lst1A.Add((int)le);
                //double h0 = LenUpper - 32 * 10 + 32 * m;
                //double w = GetXByH(x , y , h0, Radius) ;
                //double wwS = GetX2ByH(xI, yI , h0, Radius)- GetXByH(x, y, h0, Radius);
            }
            int a2 = (int)(Length - 50 * 2 - 12 * 2);
            int b2 = (int)MainRebarDB + 9 * 70;
            ini2B = b2;
            //2#
            RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, a2, b2));
            for (int m = 1; m <= count; m++)
            {
                //string no = "A";
                //byte[] array = new byte[1];
                //array[0] = (byte)(Convert.ToInt32(64 + m)); //ASCII码强制转换二进制
                //no = Convert.ToString(System.Text.Encoding.ASCII.GetString(array));
                int bb2 = (int)(Math.Round((lst1A[m - 1] / ini1A) * ini2B, 0));
                RebarList.Add(new MORebarRecord(2, m, "", eDB.DB12, 2, eShapeType.MO, a2, bb2));

            }
            int a3 = (int)(Length - 50 * 2 - 12 * 2);
            int h = 155;
            ini3A = a3;
            //3#
            RebarList.Add(new MDRRebarRecord(3, 0, "", eDB.DB12, npts, eShapeType.MDR, a3, h));
            for (int m = 1; m <= count; m++)
            {
                //string no = "A";
                //byte[] array = new byte[1];
                //array[0] = (byte)(Convert.ToInt32(64 + m)); //ASCII码强制转换二进制
                //no = Convert.ToString(System.Text.Encoding.ASCII.GetString(array));
                int aa3 = (int)(Math.Round((lst1A[m - 1] / ini1A) * ini3A, 0));
                if (m == 1)
                    RebarList.Add(new MDRRebarRecord(3, m, "", eDB.DB12, 36, eShapeType.MDR, aa3, h));
                else
                    RebarList.Add(new MDRRebarRecord(3, m, "", eDB.DB12, 2, eShapeType.MDR, aa3, h));

            }

            count = 19;
            int a4 = (int)((Width) - 50 * 2 - 12 * 2);
            int b4 = 3 * 80 + (int)MainRebarDB;
            //4#
            RebarList.Add(new MORebarRecord(4, 0, "", eDB.DB12, npts, eShapeType.MO, a4, b4));
            List<double> lstA4 = new List<double>() { 2376, 2392, 2430, 2492, 2576, 2684, 2815, 2971, 3152, 3360, 3594, 3857, 4151, 4476, 4836, 3244, 3674, 4157, 4784 };
            for (int m = 0; m < count; m++)
            {
                //string no = "A";
                //byte[] array = new byte[1];
                //array[0] = (byte)(Convert.ToInt32(64 + m)); //ASCII码强制转换二进制
                //no = Convert.ToString(System.Text.Encoding.ASCII.GetString(array));
                //int aa4 = (int)(Math.Round((lst1A[m - 1] / ini1A) * a4,0));
                int a40 = (int)(Math.Round(Math.Sqrt(Math.Pow(m * 100 - 25 * m, 2) + Math.Pow(ini1A, 2)), 0));
                //RebarList.Add(new MDRRebarRecord(4, 0, no, eDB.DB12, 1 * 2, eShapeType.MDR,aa4, h));

                if (m >= count - 4)
                {
                    RebarList.Add(new MUNRebarRecord(4, m + 1, "", eDB.DB12, 2, eShapeType.MUN, Width, b4, lstA4[m]));

                }
                else
                {
                    RebarList.Add(new MORebarRecord(4, m + 1, "", eDB.DB12, 2, eShapeType.MO, lstA4[m], b4));
                }
            }
            int a5 = (int)(900 - 50 * 2 - 12 * 2);
            int b5 = 3 * 80 + (int)MainRebarDB;
            int nptsN5 = (GetAllStirrupNum() + 3 + 1);
            //5#
            RebarList.Add(new MORebarRecord(5, 0, "", eDB.DB12, nptsN5, eShapeType.MDR, a5, 217));
            RebarList.Add(new MORebarRecord(5, 0, "a", eDB.DB12, 19, eShapeType.MDR, a5, 257));
            List<double> lstb5 = new List<double>() { 257, 282, 285, 289, 295, 304, 314, 326, 340, 356, 373, 393, 415, 437, 465, 493, 524, 557, 592 };
            for (int m = 0; m < count; m++)
            {

                RebarList.Add(new MORebarRecord(5, m + 1, "", eDB.DB12, 4, eShapeType.MO, a5, lstb5[m]));

            }
            double L1 = 8483;
            L1 = 8494;
            int len = 9000;
            int a6a = (int)(PierHeight - 5500 + 2000 - 56 - 100 - 32 - L1 - 177);
            if (a6a < 0)
            {
                int num = (int)Math.Ceiling((double)(a6a / 1000));
                L1 = 8494 + (num - 1) * 1000;
                len = 9000 + (num - 1) * 1000;
                a6a = (int)(PierHeight - 5500 + 2000 - 56 - 100 - 32 - L1 - 177);
                // 起步筋定尺9m
                //4.1a为内侧起步筋；
                RebarList.Add(new MHXRebarRecord(6, 0, "", MainRebarDB, false, 6, eShapeType.MHXe, len));

                RebarList.Add(new MHXRebarRecord(7, 1, "", MainRebarDB, true, 26, eShapeType.MHX, len + 2000));
                RebarList.Add(new MHXRebarRecord(7, 2, "", MainRebarDB, true, 32, eShapeType.MHX, len + 2000));
                //5.1b为外侧起步筋；
                RebarList.Add(new MHXRebarRecord(7, 3, "", MainRebarDB, true, 4, eShapeType.MHXe, len));
                RebarList.Add(new MHXRebarRecord(7, 4, "", MainRebarDB, false, 6, eShapeType.MHXe, len));
            }
            else
            {
                // 起步筋定尺9m
                //4.1a为内侧起步筋；
                RebarList.Add(new MHXRebarRecord(6, 0, "", MainRebarDB, false, 6, eShapeType.MHXe, 9000));

                RebarList.Add(new MHXRebarRecord(7, 1, "", MainRebarDB, true, 26, eShapeType.MHX, 11000));
                RebarList.Add(new MHXRebarRecord(7, 2, "", MainRebarDB, true, 32, eShapeType.MHX, 11000));
                //5.1b为外侧起步筋；
                RebarList.Add(new MHXRebarRecord(7, 3, "", MainRebarDB, true, 4, eShapeType.MHXe, 9000));
                RebarList.Add(new MHXRebarRecord(7, 4, "", MainRebarDB, false, 6, eShapeType.MHXe, 9000));
            }


            int nptsM = GetLowStirrupNum() * 2;


            int rr0 = RebarKnowledge.GerRadius(eDB.DB32);
            int cc0 = (int)(1500 - 100 + rr0 * 0.5 + 32);
            RebarList.Add(new MLRebarRecord(6, 0, "a", eDB.DB12, 6, eShapeType.ML, a6a, 1000, cc0, 128));



            //  1-获取承台尺寸
            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            double LConst = PierHeight - LenUpper;
            int[] value = dicRInfo.Values.ToList()[0];
            int arcR = value[0];
            int arcLength = value[1];
            int arcC = value[2];
            int arcNum = value[3];
            int A = 600;        //固定      
            int C = 45;         //固定
            C = 250;
            int D = 2400;       //固定

            int L = len + 2000;       //固定
            int r = RebarKnowledge.GerRadius(MainRebarDB);
            int d0 = 32;
            int B = L - A - C - D + r / 2 + d0;
            int aa = (int)Math.Round(LConst + FTHeight - 160 - B - 32, 0, MidpointRounding.AwayFromZero);
            if (C == 250)
                aa = (int)Math.Round(LConst + FTHeight - 160 - B - 248, 0, MidpointRounding.AwayFromZero);
            int bb = arcLength;// (int)Math.Round(arc.Length, 0, MidpointRounding.AwayFromZero);
            int cc = arcC;// 305;
            int dd = 1500 - arcC;// 1195;
            if (MainRebarDB == eDB.DB28)
                dd = 1200 - arcC;
            int rr = arcR;// (int)Math.Round(arc.Radius, 0, MidpointRounding.AwayFromZero);
            foreach (var item in dicRInfo.Keys)
            {
                value = dicRInfo[item];
                int arcr = value[0];
                bb = value[1];
                cc = value[2];
                int arcnum = value[3];
                dd = 1400 - cc;

                rr = arcr;
                string[] va = item.Split('.');

                if (va.Length == 1)
                    RebarList.Add(new MKRebarRecord(int.Parse(va[0]), 0, "", MainRebarDB, arcnum, eShapeType.MK, aa, bb, cc, dd, rr));
                else if (va.Length == 2)
                    RebarList.Add(new MKRebarRecord(int.Parse(va[0]), int.Parse(va[1]), "", MainRebarDB, arcnum, eShapeType.MK, aa, bb, cc, dd, rr));
                else if (va.Length == 3)
                    RebarList.Add(new MKRebarRecord(int.Parse(va[0]), int.Parse(va[1]), va[2], MainRebarDB, arcnum, eShapeType.MK, aa, bb, cc, dd, rr));

            }

            //RebarList.Add(new MANRebarRecord(15,1,"", MainRebarDB, 1923, 600,2,eShapeType.MAN));
            //RebarList.Add(new MANRebarRecord(15, 2, "", MainRebarDB, 2051, 600, 2, eShapeType.MAN));
            //RebarList.Add(new MANRebarRecord(15, 3, "", MainRebarDB, 2179, 600, 2, eShapeType.MAN));
            #endregion
            //if (isDiv)
            //    UAN1N2 = NumMainAll * 8;
            //else
            UAN1N2 = 106 * 4;
        }
        public override void SetRebarDistribute()
        {
            //throw new NotImplementedException();
        }
    }




}
